module.exports = app => {
  return {
    schedule: {
      cron: (app.config.env === 'prod' || app.config.env === 'st') ? '0 0 */5 * * *' : '0 0 * * * *',
      immediate: true,
      type: 'worker',
    },
    async task(ctx) {
      console.log('************ crontab 定时统计 ...' + new Date())
      function sleep(time) {
        return new Promise((resolve) => setTimeout(resolve, time))
      }
      const list = await ctx.model.Devices.find()
      for (const device of list) {
        try{
          console.log(device.deviceid)
          ctx.service.flows.getFlows(device)
        } catch (e) {
          console.log(e.toString())
        }
        await sleep(1000)
      }
    },
  }
}

